<template>
    <div class="login-main">
        <div class="find-pwd-main">
            <div class="find-pwd-box">
                <div class="title">
                    找回密码
                    <span>
                        已有帐号去
                        <router-link to="/login">登录</router-link>
                    </span>
                </div>
                <div class="find-pwd-body">
                    <div class="form-group">
                        <input type="password" placeholder="新密码" v-model="newPassword">
                    </div>
                    <div class="form-group">
                        <input type="password" placeholder="再次输入新密码" v-model="repeatPassword">
                    </div>
                    <div class="form-group">
                        <button @click="save()">
                            保存
                        </button>
                    </div>
                </div>
            </div>
            <div class="copyright">
                Copyright © 2017 上海企想信息技术有限公司. All rights reserved.
            </div>
        </div>

    </div>
</template>

<script>
export default {
  data() {
    return {
      newPassword: "",
      repeatPassword: ""
    };
  },
  computed: {},
  mounted() {},
  methods: {
    save() {
      //保存前先验证
      if (this.newPassword.trim().length < 6) {
        this.$Modal.error({
          title: "错误",
          content: "<p>密码长度至少需要6位!</p>"
        });
        return false;
      }
      if (this.newPassword != this.repeatPassword) {
        this.$Modal.error({
          title: "错误",
          content: "<p>两次输入的密码不一致!</p>"
        });
        return false;
      }

      //提交
      this.$ajax.post(
        "/api/login/info/updatePassword",
        `userId=${this.$route.query.UserId}&random=${this.$route.query
          .randomData}&password=${this.newPassword}`
      ).then(response=>{
          if(response.data.code==1){
              this.$Modal.success({
                title: "提示",
                content: response.data.msg
            });
              
          }else{
              this.$Modal.error({
              title: "错误",
              content: response.data.msg
            });
          }

      }).catch(error=>{
          this.$Modal.error({
              title: "错误",
              content: error
            });

      })
    }
  }
};
</script>

<style>

</style>
